<template>
  <div class="character-data-container">
    <div class="character-header">
      <h1>角色数据</h1>
      <div class="search-box">
        <input 
          type="text" 
          v-model="searchQuery" 
          placeholder="搜索角色..."
          @input="handleSearch"
        >
        <button class="search-btn">
          <i class="fas fa-search"></i>
        </button>
      </div>
    </div>

    <div class="filter-bar">
      <div class="filter-group">
        <label>元素类型：</label>
        <div class="element-tags">
          <button 
            v-for="element in elements" 
            :key="element"
            class="element-tag"
            :class="{ active: selectedElement === element }"
            @click="selectElement(element)"
          >
            {{ element }}
          </button>
        </div>
      </div>
      <div class="filter-group">
        <label>武器类型：</label>
        <div class="weapon-tags">
          <button 
            v-for="weapon in weapons" 
            :key="weapon"
            class="weapon-tag"
            :class="{ active: selectedWeapon === weapon }"
            @click="selectWeapon(weapon)"
          >
            {{ weapon }}
          </button>
        </div>
      </div>
    </div>

    <div class="characters-grid">
      <div 
        v-for="character in filteredCharacters" 
        :key="character.id"
        class="character-card"
        @click="selectCharacter(character)"
      >
        <div class="character-image">
          <img :src="character.avatar" :alt="character.name">
          <div class="character-rarity">
            <span v-for="n in character.rarity" :key="n" class="star">★</span>
          </div>
        </div>
        <div class="character-info">
          <h3>{{ character.name }}</h3>
          <div class="character-meta">
            <span class="element">{{ character.element }}</span>
            <span class="weapon">{{ character.weapon }}</span>
          </div>
          <div class="character-stats">
            <div class="stat">
              <span class="label">使用率</span>
              <span class="value">{{ character.usageRate }}%</span>
            </div>
            <div class="stat">
              <span class="label">胜率</span>
              <span class="value">{{ character.winRate }}%</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div v-if="selectedCharacter" class="character-detail-modal">
      <div class="modal-content">
        <button class="close-btn" @click="selectedCharacter = null">
          <i class="fas fa-times"></i>
        </button>
        
        <div class="detail-header">
          <div class="character-portrait">
            <img :src="selectedCharacter.avatar" :alt="selectedCharacter.name">
            <div class="rarity">
              <span v-for="n in selectedCharacter.rarity" :key="n" class="star">★</span>
            </div>
          </div>
          <div class="character-overview">
            <h2>{{ selectedCharacter.name }}</h2>
            <div class="meta-info">
              <span class="element">{{ selectedCharacter.element }}</span>
              <span class="weapon">{{ selectedCharacter.weapon }}</span>
            </div>
            <p class="description">{{ selectedCharacter.description }}</p>
          </div>
        </div>

        <div class="detail-content">
          <div class="content-section">
            <h3>基础属性</h3>
            <div class="stats-grid">
              <div v-for="(value, key) in selectedCharacter.baseStats" :key="key" class="stat-item">
                <span class="stat-label">{{ key }}</span>
                <span class="stat-value">{{ value }}</span>
              </div>
            </div>
          </div>

          <div class="content-section">
            <h3>技能详情</h3>
            <div class="skills-list">
              <div v-for="skill in selectedCharacter.skills" :key="skill.id" class="skill-card">
                <div class="skill-header">
                  <img :src="skill.icon" :alt="skill.name" class="skill-icon">
                  <div class="skill-info">
                    <h4>{{ skill.name }}</h4>
                    <span class="skill-type">{{ skill.type }}</span>
                  </div>
                </div>
                <p class="skill-description">{{ skill.description }}</p>
                <div class="skill-stats">
                  <div v-for="(value, key) in skill.stats" :key="key" class="skill-stat">
                    <span class="stat-label">{{ key }}</span>
                    <span class="stat-value">{{ value }}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="content-section">
            <h3>培养材料</h3>
            <div class="materials-list">
              <div v-for="material in selectedCharacter.materials" :key="material.id" class="material-card">
                <img :src="material.icon" :alt="material.name" class="material-icon">
                <div class="material-info">
                  <span class="material-name">{{ material.name }}</span>
                  <span class="material-count">x{{ material.count }}</span>
                </div>
                <div class="material-sources">
                  <span v-for="source in material.sources" :key="source" class="source-tag">
                    {{ source }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'

const searchQuery = ref('')
const selectedElement = ref('')
const selectedWeapon = ref('')
const selectedCharacter = ref(null)

const elements = ['火', '水', '风', '雷', '冰', '岩', '草']
const weapons = ['单手剑', '双手剑', '长柄武器', '法器', '弓箭']

// 模拟角色数据
const characters = ref([
  {
    id: 1,
    name: '伊莉雅',
    avatar: '/characters/elisa.jpg',
    element: '火',
    weapon: '单手剑',
    rarity: 5,
    usageRate: 45.8,
    winRate: 52.3,
    description: '来自异世界的魔法少女，擅长使用火焰魔法。',
    baseStats: {
      '生命值': '12000',
      '攻击力': '2800',
      '防御力': '800',
      '暴击率': '25%',
      '暴击伤害': '150%'
    },
    skills: [
      {
        id: 1,
        name: '元素爆发',
        type: '主动技能',
        icon: '/skills/burst.jpg',
        description: '释放强大的元素能量，对范围内敌人造成大量伤害。',
        stats: {
          '伤害倍率': '350%',
          '冷却时间': '12秒',
          '元素消耗': '60'
        }
      }
    ],
    materials: [
      {
        id: 1,
        name: '元素结晶',
        icon: '/materials/crystal.jpg',
        count: 168,
        sources: ['元素副本', '世界BOSS']
      }
    ]
  }
])

const filteredCharacters = computed(() => {
  return characters.value.filter(character => {
    const matchesSearch = character.name.toLowerCase().includes(searchQuery.value.toLowerCase())
    const matchesElement = !selectedElement.value || character.element === selectedElement.value
    const matchesWeapon = !selectedWeapon.value || character.weapon === selectedWeapon.value
    return matchesSearch && matchesElement && matchesWeapon
  })
})

const handleSearch = () => {
  // 实现搜索逻辑
}

const selectElement = (element: string) => {
  selectedElement.value = selectedElement.value === element ? '' : element
}

const selectWeapon = (weapon: string) => {
  selectedWeapon.value = selectedWeapon.value === weapon ? '' : weapon
}

const selectCharacter = (character: any) => {
  selectedCharacter.value = character
}
</script>

<style scoped>
.character-data-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.character-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.character-header h1 {
  margin: 0;
  color: #2c3e50;
}

.search-box {
  display: flex;
  gap: 0.5rem;
}

.search-box input {
  width: 300px;
  padding: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.search-btn {
  padding: 0.8rem;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.filter-bar {
  background: #f5f5f5;
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 2rem;
}

.filter-group {
  margin-bottom: 1rem;
}

.filter-group:last-child {
  margin-bottom: 0;
}

.filter-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
}

.element-tags,
.weapon-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.element-tag,
.weapon-tag {
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.element-tag.active,
.weapon-tag.active {
  background: #42b983;
  color: white;
  border-color: #42b983;
}

.characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.character-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.3s;
}

.character-card:hover {
  transform: translateY(-4px);
}

.character-image {
  position: relative;
  padding-top: 100%;
}

.character-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character-rarity {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.2rem;
}

.star {
  color: #ffd700;
  font-size: 1.2rem;
}

.character-info {
  padding: 1rem;
}

.character-info h3 {
  margin: 0 0 0.5rem;
  color: #2c3e50;
}

.character-meta {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.element,
.weapon {
  padding: 0.2rem 0.5rem;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
}

.character-stats {
  display: flex;
  gap: 1rem;
}

.stat {
  flex: 1;
  text-align: center;
}

.stat .label {
  display: block;
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 0.2rem;
}

.stat .value {
  font-size: 1.1rem;
  font-weight: 500;
  color: #2c3e50;
}

.character-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 1000px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #666;
  cursor: pointer;
}

.detail-header {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
}

.character-portrait {
  width: 200px;
  position: relative;
}

.character-portrait img {
  width: 100%;
  border-radius: 8px;
}

.rarity {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.2rem;
}

.character-overview {
  flex: 1;
}

.character-overview h2 {
  margin: 0 0 1rem;
  color: #2c3e50;
}

.meta-info {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.description {
  color: #666;
  line-height: 1.6;
}

.content-section {
  margin-bottom: 2rem;
}

.content-section h3 {
  margin: 0 0 1rem;
  color: #2c3e50;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #eee;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  padding: 0.8rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.stat-label {
  color: #666;
}

.stat-value {
  font-weight: 500;
  color: #2c3e50;
}

.skills-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.skill-card {
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.skill-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.skill-icon {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.skill-info h4 {
  margin: 0 0 0.3rem;
  color: #2c3e50;
}

.skill-type {
  font-size: 0.9rem;
  color: #666;
}

.skill-description {
  margin: 0 0 1rem;
  color: #666;
}

.skill-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}

.skill-stat {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  background: white;
  border-radius: 4px;
}

.materials-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.material-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.material-icon {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.material-info {
  flex: 1;
}

.material-name {
  display: block;
  font-weight: 500;
  color: #2c3e50;
}

.material-count {
  font-size: 0.9rem;
  color: #666;
}

.material-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.source-tag {
  padding: 0.2rem 0.5rem;
  background: white;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
}
</style> 